<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('posts', function(Blueprint $table)
		{
			$table->increments('id');
            $table->tinyInteger('post_type');
            $table->integer('post_category');
            $table->integer('post_group_id');
            $table->integer('creator_id');
            $table->integer('province_id')->nullable();
            $table->integer('city_id')->nullable();
            $table->string('title')->nullable();
            $table->text('content');
            $table->string('contact');
            $table->string('post_attachment_file_path');

			$table->timestamps();
            $table->softDeletes();

            $table->index(array('post_type', 'post_category'));
            $table->index(array('post_type', 'post_group_id'));
		});

        Schema::create('post_extras', function(Blueprint $table){
            $table->increments('id');
            $table->integer('post_id');
            $table->integer('views_count');
            $table->integer('comments_count');
            $table->integer('likes_count');
            $table->integer('collects_count');
            $table->integer('last_comment_user_id');
            $table->timestamps();

            $table->softDeletes();

            $table->unique('post_id');
        });
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::dropIfExists('posts');

        Schema::dropIfExists('post_extras');
	}

}
